package cn.com.yunhe.controller;

import cn.com.yunhe.bean.CCarGuobiao;
import cn.com.yunhe.service.CCarGuobiaoService;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 赵长松
 * @Date: 2019/1/9 10:17
 * @Version 1.0
 */
@RestController
public class CCarGuobiaoController {
    @Resource
    private CCarGuobiaoService carGuobiaoService;
    @RequestMapping("/guobiaolist")
    private ModelAndView guobiaolist(){//进入排放标准首页面
        return new ModelAndView("houtai/guobiaolist");
    }
    @RequestMapping("/guobiaoadd")
    private ModelAndView guobiaoadd(){//进入增加排放标准的页面
        return new ModelAndView("houtai/guobiaoadd");
    }
    @RequestMapping("/addguobiao")
    public ModelAndView addCarGuoBiao(CCarGuobiao carGuobiao){//插入
        Integer integer = carGuobiaoService.addCCarGuobiao(carGuobiao);
        System.out.println("插入状态："+integer);
        return new ModelAndView("houtai/guobiaolist");
    }
    @RequestMapping("/queryguobiao")
    public List<CCarGuobiao> queryguobiao(CCarGuobiao carGuobiao){//查询
        Map<String,String> map = new HashMap<>();
        map.put("guoji",carGuobiao.getGuoji());
        List<CCarGuobiao> cCarGuobiaos = carGuobiaoService.queryAllCarGuobiao(map);
        System.out.println(cCarGuobiaos);
        return cCarGuobiaos;
    }
    @RequestMapping("/queryoneguobiao")
    public ModelAndView queryOneGuoBiao(CCarGuobiao carGuobiao){//获得修改某一排放的具体信息
        System.out.println("id为："+carGuobiao.getId());
        CCarGuobiao cCarGuobiao = carGuobiaoService.queryOneGuobiao(carGuobiao.getId());
        System.out.println(cCarGuobiao);
        ModelMap modelMap = new ModelMap();
        modelMap.addAttribute("cCarGuobiao",cCarGuobiao);
        return new ModelAndView("houtai/guobiaoedit",modelMap);
    }
    @RequestMapping("/updateguobiao")
    public ModelAndView updateguobiao(CCarGuobiao carGuobiao){
        Integer integer = carGuobiaoService.UpdateCarGuobiao(carGuobiao);
        System.out.println("修改状态为："+integer);
        return new ModelAndView("houtai/guobiaolist");
    }
    @RequestMapping("/delguobiao")
    public Boolean delguobiao(CCarGuobiao carGuobiao){
        Boolean bool;
        Integer integer = carGuobiaoService.delCarGuobiao(carGuobiao);
        System.out.println("删除状态："+integer);
        if (integer>0){
            bool=true;
        }else{
            bool=false;
        }
        return bool;
    }
}
